package com.woniu.defecttracking.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.defecttracking.dto.GetWorkHoursByDayDto;
import com.woniu.defecttracking.dto.GetWorkLogByMonthDto;
import com.woniu.defecttracking.entity.WorkLog;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.woniu.defecttracking.param.GetWorkLogByDayParam;
import com.woniu.defecttracking.param.GetWorkLogByMonthParam;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author tiangle
 * @since 2021-12-31
 */
public interface WorkLogMapper extends BaseMapper<WorkLog> {



    @Select("SELECT sum(work_hours) from work_log_Moth where bug_id=#{bugId}")
    Double selectTotalHoursByBugId(Integer bugId);

    @Select("select project_name,MODIFY_person,modify_time,sum(hours) hours\n" +
            "from work_log_ByDate GROUP BY modify_Time,project_name,MODIFY_person ORDER BY modify_time")
    IPage<GetWorkHoursByDayDto> selectAllWorkLogs(Page<?> page);

    @Select("select project_name,modify_person,modify_time,sum(hours) hours\n" +
            "from work_log_ByMonth \n" +
            "GROUP BY project_name,modify_person,modify_time ORDER BY modify_time")
    IPage<GetWorkLogByMonthDto> selectAllWorkLogsMonthes(Page<?> page);


    IPage<GetWorkHoursByDayDto> selectAllByDayAndKeys(@Param("page") Page<GetWorkHoursByDayDto> page,@Param("keyWords") GetWorkLogByDayParam getWorkLogByDayParam);

    IPage<GetWorkLogByMonthDto> selectAllByMonthAndKeys(@Param("page") Page<GetWorkLogByMonthDto> page,@Param("keyWords") GetWorkLogByMonthParam getWorkLogByMonthParam);

    @Select("SELECT * from work_log where  bug_id=#{bugid}")
    List<WorkLog> selectListByBugId(Integer bugid);
}
